//
//  Service.m
//  reSearchDemo
//
//  Created by 云库 on 15/7/20.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "Service.h"
#import "MButton.h"
#import "SearchAllViewController.h"
#import "ServicerCell.h"
#import "LoginController.h"
#import "UIImageView+WebCache.h"
#import "RegisteredServiceVC.h"
#import "ServiceVC.h"
#import "MenuView.h"
@interface Service ()<UINavigationControllerDelegate>{
    UIView  * actionBar;
}
@property(nonatomic,strong)MenuView *menuView;
@end

@implementation Service

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIView * actionbar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 44)];
    self.navigationItem.titleView = actionbar;
    [self setRightBarButton:@"成为服务商" selector:@selector(rightBarButtonClick)];
    actionBar = actionbar;
    // left icon
//    UIImageView * icon = [[UIImageView alloc] initWithImage:LOADIMAGE(@"actionbar_icon")];
//    icon.frame = CGRectMake(8, 10, 24, 24);
//    [actionbar addSubview:icon];
    UILabel * lab=[[UILabel alloc]initWithFrame:CGRectMake(8, 0, 60, 40)];
    lab.text=@"服务商";
    lab.font=[UIFont systemFontOfSize:20];
    lab.textColor=[UIColor whiteColor];
    [actionbar addSubview:lab];
    
    MButton  * titleButton =[[MButton alloc] initWithFrame:CGRectMake(0, 0, self.view.width-120, 44)];
    
    titleButton.arrangement = MButtonContentArrangementHorizontal;
//    [titleButton setImageShowSize:CGSizeMake(30, 30)];
    [titleButton setTitle:@"搜索服务商" forState:UIControlStateNormal];
    [titleButton layoutIfNeeded];
    
//    [titleButton setImage:LOADIMAGE(@"actionbar_search_icon") forState:UIControlStateNormal];
    [titleButton addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside];
    [actionbar addSubview:titleButton];
    
    
    //
    //    [UILabel linesText:AppDisplayName font:[UIFont boldSystemFontOfSize:18] wid:100 lines:0 color:[UIColor whiteColor]];
    
    
    //    titleButton.origin = CGPointMake((actionbar.width - titleButton.width)/2 - 20, 0);
    //    [actionbar addSubview:titleButton];
    
//    int i = 0;
    //    UIButton * btn = [self buttonInActionbar:i++ actionbar:actionbar];
    //    [btn setImage:LOADIMAGE(@"actionbar_search_icon") forState:UIControlStateNormal];
    //
//    UIButton *btn = [self buttonInActionbar:i++ actionbar:actionbar];
//    [btn setImage:LOADIMAGE(@"actionbar_add_icon") forState:UIControlStateNormal];
    LoginController  * vc=[[LoginController alloc]init];
    if (isLogin) {
        [self pushViewController:vc];
    }else{
        [self buildMainView];
    }
}
-(void)buildMainView{
    UIButton * manageSelfMall=[UIButton buttonWithType:UIButtonTypeSystem];
    manageSelfMall.frame=CGRectMake(self.view.frame.size.width/2-130, 64+30, 260, 60);
    [manageSelfMall setTitle:@"管理我的服务商" forState:UIControlStateNormal];
    [manageSelfMall addTarget:self action:@selector(manageSelfMallClick) forControlEvents:UIControlEventTouchUpOutside];
    manageSelfMall.tintColor=[UIColor blackColor];
    manageSelfMall.titleLabel.font=[UIFont systemFontOfSize:25];
    manageSelfMall.backgroundColor=[UIColor greenColor];
    [self.view addSubview:manageSelfMall];
    UILabel * lab=[[UILabel alloc]initWithFrame:CGRectMake(5, manageSelfMall.frame.origin.y+manageSelfMall.frame.size.height+30, 180, 20)];
    lab.text=@"你身边的服务商";
    [self.view addSubview:lab];
    
    UITableView * servicerTable=[[UITableView alloc]initWithFrame:CGRectMake(0, lab.frame.origin.y+lab.frame.size.height, self.view.frame.size.width, 100)];
    servicerTable.delegate=self;
    servicerTable.dataSource=self;
    servicerTable.rowHeight=100;
    [self.view addSubview:servicerTable];
    [servicerTable registerClass:[ServicerCell class] forCellReuseIdentifier:@"cell"];
    
    
}
#pragma mark - UITableViewDelegate & UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ServicerCell * cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.user=@"";
    return  cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _menuView.buttonView) {
        return 44;
    } else {
        return 100;
    }
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (tableView == _menuView.buttonView) {
        switch (indexPath.row) {
            case 0:
            {
                [self pushViewController:[ServiceVC new]];
                break;
            }
            case 1:
            {
                [self pushViewController:[RegisteredServiceVC new]];
                break;
            }
                
                
            default:
                break;
        }
    }
}
#pragma mark - ButtonClickMethod
-(void)search
{
    SearchAllViewController * con = [[SearchAllViewController alloc] init];
    [self pushViewController:con];
}
//- (UIButton*)buttonInActionbar:(int)number actionbar:(UIView*)actionbar{
//    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    btn.tag = number;
//    [btn setImage:LOADIMAGE(@"actionbar_add_icon") forState:UIControlStateNormal];
//    btn.frame = CGRectMake(self.view.width - 44, 6, 32, 32);
//    [actionbar addSubview:btn];
//    [btn addTarget:self action:@selector(btnItemPressed:) forControlEvents:UIControlEventTouchUpInside];
//    return btn;
//}
-(void)rightBarButtonClick{
    
    NSArray * arr = nil;
    arr = @[@"已登录页面", @"未登录页面"];
    _menuView = [[MenuView alloc] initWithButtonTitles:arr withDelegate:self];
    _menuView.hasImage = NO;
    [_menuView showInView:self.view origin:CGPointMake(self.view.width - 180, 70)];
    _menuView.buttonView.delegate=self;
}

-(void)manageSelfMallClick{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
